package com.github.codemperor.core.lock;

import com.github.codemperor.core.lock.redis.LockContext;

/**
 * 锁的操作
 */
public class LockConfiguration {
    /**
     * 锁的唯一表示
     */
    private String lockKey;

    /**
     * 锁的过期时间(S) 秒
     */
    private int expireSec = 40;

    /**
     * 线程等是否开启等待，如果开启，需要设置线程等待时间waitingSec，默认不开启等待
     */
    private boolean waitingEnabled = false;

    /**
     * 线程等待时间（s 秒）,如果小于expireSec， 则当用户忘记解锁时，其他线程永远不会执行业务，会过期。因为过期时间大于等待时间，请根据场景设定
     */
    private int waitingSec = 20;

    public String getLockKey() {
        return lockKey;
    }

    public LockConfiguration setLockKey(String lockKey) {
        this.lockKey = lockKey;
        return this;
    }

    public int getExpireSec() {
        return expireSec;
    }

    public LockConfiguration setExpireSec(int expireSec) {
        this.expireSec = expireSec <= 0 ? LockContext.maxExpire : expireSec; //不可为0，如果为0，默认最大超时时间
        return this;
    }

    public boolean isWaitingEnabled() {
        return waitingEnabled;
    }

    public LockConfiguration setWaitingEnabled(boolean waitingEnabled) {
        this.waitingEnabled = waitingEnabled;
        return this;
    }

    public int getWaitingSec() {
        return waitingSec;
    }

    public LockConfiguration setWaitingSec(int waitingSec) {
        this.waitingSec = waitingSec;
        return this;
    }
}
